package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.newserverwelfare.NewServerWelfareReward;
import com.yanqu.road.entity.player.UserOnlineTime;
import com.yanqu.road.pb.activity.NewServerWelfareProto;

import java.util.Map;

public class NewServerWelfarePb {
    public static NewServerWelfareProto.SyncActivityDataRespMsg.Builder createSyncData
            (long userOnlineTime, Map<Integer, Map<Integer, NewServerWelfareReward>> rewardMap) {

        NewServerWelfareProto.SyncActivityDataRespMsg.Builder allBuilder = NewServerWelfareProto.SyncActivityDataRespMsg.newBuilder();
        //每个小活动遍历
        for (Map.Entry<Integer, Map<Integer, NewServerWelfareReward>> singleTypeEntry : rewardMap.entrySet()) {
            NewServerWelfareProto.WelfareRewardRemainMsg.Builder builder = NewServerWelfareProto.WelfareRewardRemainMsg.newBuilder();
            builder.setType(singleTypeEntry.getKey());
            //取出单一小活动每条剩余信息遍历
            Map<Integer, NewServerWelfareReward> singleTypeRewardMap = singleTypeEntry.getValue();
            for (Map.Entry<Integer, NewServerWelfareReward> entry : singleTypeRewardMap.entrySet()) {
                NewServerWelfareProto.WelfareSingleRewardRemainMsg.Builder singleRewardRemainMsg = NewServerWelfareProto.WelfareSingleRewardRemainMsg.newBuilder();
                singleRewardRemainMsg.setConditionId(entry.getKey());
                singleRewardRemainMsg.setRemainReward(entry.getValue().getRewardRemain());
                builder.addWelfareRemain(singleRewardRemainMsg);
            }
            //加入大消息
            allBuilder.addServerRewardData(builder);

        }
        //加入在线时间
        allBuilder.setOnlineTime(userOnlineTime);
        return allBuilder;
    }


}
